package vn.evolus.pencil.controller;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import vn.evolus.pencil.model.User;
import vn.evolus.pencil.service.UserService;


@Controller
@RequestMapping(value = "/account")
public class AccountController {
	
	@Autowired
	private UserService userService;
	
	@RequestMapping(value = "/signup", method = RequestMethod.GET)
	public String signUpGet(){
		return "user/signup";
	}
	
	@RequestMapping(value = "/signup", method = RequestMethod.POST)
	public String signUpPost(HttpServletRequest request, Model model){
		String email = (String) request.getParameter("email");
		String username = (String) request.getParameter("username");
		String password = (String) request.getParameter("password");
		
		
		User user = new User();
		user.setEmail(email);
		user.setDisplayName(username);
		user.setUsername(username);
		user.setPassword(password);
		user.setEnabled(true);
		
		userService.saveUser(user);
		
		return "login/login";
		//return "redirect:/login";
	}
}
